package com.xz.group12306.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xz.group12306.business.service.ManagerService;
import com.xz.group12306.business.service.impl.ManagerServiceImpl;
import com.xz.group12306.domain.User;

/**
 * 管理员查询用户Servlet
 */
@WebServlet("/ManageQurySutiServlet")
public class ManageQurySutiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 构造方法
	 */
	public ManageQurySutiServlet() {
		super();
	}

	/**
	 * doGet()方法
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * doPost()方法
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/**
		 * 创建一个ManagerService实例(对象)
		 */
		ManagerService managerService=new ManagerServiceImpl();
		
		/**
		 * 从表单获取数据
		 */
		int pageSize = Integer.parseInt(request.getParameter("pageSize"));
		int start = Integer.parseInt(request.getParameter("start"));

		String userName = request.getParameter("userName");
		String sex = request.getParameter("sex");
		String certType = request.getParameter("certType");
		String cert = request.getParameter("cert");

		User user = new User();
		user.setUsername(userName);
		user.setSex(sex);

		user.setCertType(certType);
		user.setCert(cert);

		List<User> users = managerService.findUserList(user, start, pageSize);

		HttpSession session = request.getSession();

		session.setAttribute("users", users);
		response.sendRedirect("admin/ManageQuery.jsp");
		

	}

}
